<template>
  <div class="cc-page-wrap">
    <div class="cc-page-card">
      <table-search @mitForm="mitForm" />
    </div>
    <div class="cc-page-card">
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="id" label="id">
        </el-table-column>
        <el-table-column prop="author" label="author">
        </el-table-column>
        <el-table-column prop="title" label="title">
        </el-table-column>
        <el-table-column prop="content_short" label="title">
        </el-table-column>
        <el-table-column prop="display_time" label="title">
        </el-table-column>
        <el-table-column prop="type" label="title">
        </el-table-column>
      </el-table>
      <PaginationLimt v-model:page="serach.pageIndex" v-model:limit="serach.pageLimit" :total="totalVal"
        @pagination="pagination"></PaginationLimt>
    </div>
  </div>
</template>
<script lang="ts">
  import {
    defineComponent,
    getCurrentInstance,
    onMounted,
    reactive,
    ref
  } from 'vue'
  import PaginationLimt from '@/components/Pagination/index.vue'
  import TableSearch from './components/TableSearch.vue'
  import {
    tableList
  } from '@/api/table'
  export default defineComponent({
    name: 'TbaleBasic',
    components: {
      PaginationLimt,
      TableSearch
    },
    setup() {
      const app = getCurrentInstance()
      // 定义table数据
      let tableData = ref([])
      let serach = reactive({
        pageIndex: 1,
        pageLimit: 10
      })
      let totalVal = ref(0)
      // init
      let initdata = () => {
        tableList(serach).then(res => {
          const {
            data,
            total
          } = res
          totalVal.value = total
          console.log(data)
          tableData.value = data
        }).catch(error => {})
      }
      // page
      let pagination = (val) => {
        serach.pageIndex = val.page
        serach.pageLimit = val.limit
        console.log(serach)
        initdata()
      }
      onMounted(() => {
        initdata()
      })
      const mitForm = (val: any) => {
        console.log(app)
        let result = !Object.values(val).every(item => item === '');
        console.log(result, 'result')
        serach = {
          ...serach,
          ...val
        }
        // serach.pageIndex = 1
        console.log(serach)
      }
      return {
        initdata,
        mitForm,
        tableData,
        serach,
        totalVal,
        pagination
      }
    }
  })
</script>

<style lang="scss" scoped>

</style>